package com.shenzhen.horselive.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.flqy.baselibrary.utils.GlideHelper;
import com.shenzhen.horselive.R;
import com.shenzhen.horselive.beans.ProfitRankingBean;

import org.jetbrains.annotations.NotNull;

import java.text.NumberFormat;

public class CityPartnerAdapter extends BaseQuickAdapter<ProfitRankingBean.DataBean, BaseViewHolder> {
    public CityPartnerAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, ProfitRankingBean.DataBean s) {
           switch (baseViewHolder.getAdapterPosition())
           {
               case 1:
                   baseViewHolder.setVisible(R.id.tv_number,false);
                   baseViewHolder.setVisible(R.id.img_logo,true);
                   baseViewHolder.setImageResource(R.id.img_logo,R.mipmap.ico_item_city_logo1);
                   break;
               case 2:
                   baseViewHolder.setVisible(R.id.tv_number,false);
                   baseViewHolder.setVisible(R.id.img_logo,true);
                   baseViewHolder.setImageResource(R.id.img_logo,R.mipmap.ico_item_city_logo3);
                   break;
               case 3:
                   baseViewHolder.setVisible(R.id.tv_number,false);
                   baseViewHolder.setVisible(R.id.img_logo,true);
                   baseViewHolder.setImageResource(R.id.img_logo,R.mipmap.ico_item_city_logo2);
                   break;
               default:
                   baseViewHolder.setVisible(R.id.tv_number,true);
                   baseViewHolder.setVisible(R.id.img_logo,false);
                   baseViewHolder.setText(R.id.tv_number,baseViewHolder.getAdapterPosition()+"");
                   break;
           }

           if (s!=null)
           {
           baseViewHolder.setText(R.id.tv_time,"解封时间："+s.getExpirationTime())
                   .setText(R.id.tv_name,s.getUserName())
                   .setText(R.id.tv_addr,s.getAreaName())
                   .setText(R.id.tv_money,formatNum(s.getFzValue())+"(蜂值)");
        GlideHelper.loadAdvertImage(s.getHeadImg(),baseViewHolder.getView(R.id.img_user));
           }

    }

    private  String  formatNum(String  num)
    {
        if (num!=null)
        {
        NumberFormat  format = NumberFormat.getInstance();
        format.setMaximumFractionDigits(10);
        return format.format(Double.parseDouble(num));
        }
        else
        {
            return null;
        }
    }

}
